package havaAtalk2;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class Server {
    public static void main(String[] args) throws Exception {
        DatagramSocket socket = new DatagramSocket(8888);
        System.out.println("聊天室开启....");
        while (true) {
            DatagramPacket packet = new DatagramPacket(new byte[1024], 1024);
            socket.receive(packet);
            byte[] data = packet.getData();
            String s = new String(data, 0, packet.getLength());
            InetAddress address = packet.getAddress();
            String hostAddress = address.getHostAddress();
            int port = packet.getPort();
            System.out.println("IP地址" + hostAddress + "的" +port+"端口发来信息： " + s);
        }
    }

}
